import os
import shutil
import threading
import time

import pyautogui

wxwork_global_path = r'C:\Users\hn\Documents\WXWork\Global'


def clear_global(global_dir_path):
    """
    清理golbal文件夹
    :param global_dir_path:golbal文件夹路径
    :return:
    """
    global_path_list = os.listdir(global_dir_path)

    for i in global_path_list:

        global_path = global_dir_path + '\\' + i
        if os.path.isdir(global_path):
            print(global_path)
            # 删除目录
            shutil.rmtree(global_path)
            print(str(global_path) + ":这个目录删除成功")
        else:

            os.remove(global_path)
            print(str(global_path) + " 这是个文件")

    pyautogui.alert(title='信息', text='global文件删除成功')


def clear_wxwork():
    if os.path.exists(wxwork_global_path):
        # 关闭所有企微
        os.system('taskkill /F /IM WXWork.exe')
        time.sleep(3)
        # 遍历 global目录中所有的文件和目录
        clear_global(wxwork_global_path)
    else:
        wxwork_global_path1 = pyautogui.prompt(text='请输入正确的文件路径', title='选择global路径', default='')
        print(wxwork_global_path1)
        if wxwork_global_path1.split('\\')[-1] == 'Global':
            # 关闭所有企微
            os.system('taskkill /F /IM WXWork.exe')
            time.sleep(3)
            clear_global(wxwork_global_path1)
        else:
            print('路径有误')


